package com.redoor.iot.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * 
 * @author Administrator
 *
 */
@Component
@Aspect
public class LogAspect {
	
	private Logger logger = LoggerFactory.getLogger(getClass());
	
	@Pointcut("@annotation(com.redoor.iot.aspect.Log)")
	private void cut() { }  
	
	/**
	 * 
	 * @param joinPoint
	 * @return  Object  *************************此方法必须返回Object，否则@ResponseBody注解失效，无法返回json信息***************************
	 */
	@Around("cut()")
	public Object advice(ProceedingJoinPoint joinPoint){
		
		logger.info("环绕通知之开始");
		Object obj = null;
	    try {
	        obj = joinPoint.proceed();
	    } catch (Throwable e) {
	        logger.error("logAspect异常",e);
	    }
	    logger.info("环绕通知之结束");
	    
	    return obj;
	}
}